package com.ebelter.bodyfatscale.ui.activity;


import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.bodyfatscale.R;
import com.ebelter.bodyfatscale.common.Constants;
import com.ebelter.bodyfatscale.moudules.db.beans.HistoryMesureData;
import com.ebelter.bodyfatscale.ui.pager.main.DashboardPager;
import com.ebelter.bodyfatscale.util.NumUtils;
import com.ebelter.bodyfatscale.util.ScaleBaseUtils;
import com.ebelter.bodyfatscale.util.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class HistoryItemDetailActivity extends BaseActivity {

    private static final String TAG = "HistoryListActivity";
    @BindView(R.id.modify_back_bt)
    ImageView back_iv;
    public static final String ITEMDATD = "d";

    @BindView(R.id.hostory_d_time_tv)
    TextView hostory_d_time_tv;


    @BindView(R.id.hostory_weight_tv)
    TextView hostory_weight_tv;

    @BindView(R.id.hostory_bodyfatpercentage_tv)
    TextView hostory_bodyfatpercentage_tv;

    @BindView(R.id.hostory_bmi_tv)
    TextView hostory_bmi_tv;

    @BindView(R.id.hostory_bmr_tv)
    TextView hostory_bmr_tv;

    @BindView(R.id.hostory_musclemass_tv)
    TextView hostory_musclemass_tv;

    @BindView(R.id.hostory_bonemincontent_tv)
    TextView hostory_bonemincontent_tv;

    @BindView(R.id.hostory_protein_tv)
    TextView hostory_protein_tv;

    @BindView(R.id.hostory_bodywaterpercentage_tv)
    TextView hostory_bodywaterpercentage_tv;

    @BindView(R.id.hostory_skeletal_tv)
    TextView hostory_skeletal_tv;

    @BindView(R.id.hostory_vfl_tv)
    TextView hostory_vfl_tv;

    private String unitKg = StringUtils.getResStr(R.string.kg);
    private String unitLb = StringUtils.getResStr(R.string.lb);

    private void setDatas(HistoryMesureData itemData) {
        hostory_d_time_tv.setText(ScaleBaseUtils.timeFatmat(itemData.measureTime,3));//时间
        float w= NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat((float) itemData.weight),1);
        hostory_weight_tv.setText(numFatmat(w,Constants.isKgUnit?unitKg:unitLb));//体重

        float fat=NumUtils.numBaoLiuWei((float) itemData.fat,1);
        hostory_bodyfatpercentage_tv.setText(numFatmat2(fat,"%"));//内脂


        float bmi=NumUtils.numBaoLiuWei((float) itemData.bmi,1);
        hostory_bmi_tv.setText(numFatmat(bmi,""));

        int bmr= (int) itemData.bmr;
        hostory_bmr_tv.setText(numFatmat2(bmr,"kcal/d"));

        float vfl=NumUtils.numBaoLiuWei((float) itemData.visceralFat,1);
        hostory_vfl_tv.setText(numFatmat(vfl,""));

        float m= NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat((float) itemData.muscleVolume),1);
        hostory_musclemass_tv.setText(numFatmat(m,Constants.isKgUnit?unitKg:unitLb));

        float b= NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat((float) itemData.boneVolume),1);
        hostory_bonemincontent_tv.setText(numFatmat(b,Constants.isKgUnit?unitKg:unitLb));

        float pr=NumUtils.numBaoLiuWei((float) itemData.protein,1);
        hostory_protein_tv.setText(numFatmat2(pr,"%"));

        float moisture=NumUtils.numBaoLiuWei((float) itemData.waterRate,1);
        hostory_bodywaterpercentage_tv.setText(numFatmat2(moisture,"%"));//水分

        float g= NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat((float) itemData.boneVolume),1);
        hostory_skeletal_tv.setText(numFatmat(g,Constants.isKgUnit?unitKg:unitLb));//gu
    }

    private String numFatmat(float value,String unit){
        if (value<=0){
            return DashboardPager.NO_RESULT;
        }else {
            if (TextUtils.equals(unit,unitLb)){
                return ScaleBaseUtils.unitDisplay2(value+"",unitLb);
            }
            return value+unit;
        }
    }


    private String numFatmat2(float value,String unit){
        if (value<=0){
            return DashboardPager.NO_RESULT;
        }else {
            return ScaleBaseUtils.unitDisplay2(value+"",unit);
        }
    }
    private String numFatmat2(int value,String unit){
        if (value<=0){
            return DashboardPager.NO_RESULT;
        }else {
            return ScaleBaseUtils.unitDisplay2(value+"",unit);
        }
    }

    @Override
    protected int loadLayoutById() {
        return R.layout.hostoryitemdetail_ly;
    }

    @Override
    protected void initViews() {}

    HistoryMesureData itemData;
    @Override
    protected void initData() {
        itemData = (HistoryMesureData) getIntent().getSerializableExtra(ITEMDATD);
        if (itemData==null){
            finish();
            return;
        }
        setDatas(itemData);
    }




    @OnClick({ R.id.modify_back_bt})
    public void btClick(View view){
        switch (view.getId()){
            case R.id.modify_back_bt:
                finish();
                break;
        }
    }




}
